import axios from 'axios'


const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 500000000 // request timeout
})



const token: string = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJoeXlxMDJfMTgxNTgyMDIwODciLCJkYXRhX3Njb3BlcyI6bnVsbCwibW9iaWxlIjoiMTgxNTgyMDIwODciLCJyZWZfY29kZSI6bnVsbCwiY2xpZW50X2lkIjoiY2xpZW50X2h5eXEwMiIsImxpY2Vuc2UiOiJtYWRlIGJ5IGh1eXVuIiwidXNlcl90eXBlIjoiY3VzdG9tZXIiLCJ1c2VyX2NvZGUiOiJjejAxXzEzNjg4Nzk4NjEwNDc3MDk2OTciLCJzY29wZSI6WyJjdXN0b21lciJdLCJtYW5hZ2VyX2ZsYWciOiIwIiwiZXhwIjoxNjM5MTg2ODQ0LCJkZXB0X2lkIjpudWxsLCJqdGkiOiIzZmI4MTkwYy03MGI1LTQ5NWYtOThhMC1kNGVmZDg3NjE3MDAiLCJhcHBfY29kZSI6Imh5eXEwMiJ9.b6GrsKS9sRRpWxjZ0LFF0HGfnpfdgJjSO8s91JYBYOB3795k0vH-kXmrM4GEf9d6hUxNcwTfumPbSn_6fh16QhtdJbYcC8aBM2YCaxaL3GPDfZNxkv8i8hTtaiBA-qi_O3-OcBH-cBVo692pYE8egeibaP_DfMQOBlJ1x90kz_7Hoj426Gi1jUkXaLv_TzzLOFh2JG38sjdra6g3GqU-65Vi0jyOcQrq4416n6fYTY0lylFwjH5oiE-IaIDW83HJ0CigvKciq6mEeIvzEz9y6k4aC19WYjbKcQs-ruXVGEgB_tPB2fzQq3eyS4RXictKF4jWfZfJ9qJUm5fjMLicZQ'


// 请求拦截器
service.interceptors.request.use(
  (config: any) => {
    config.headers['Authorization'] = 'Bearer ' + token// 让每个请求携带自定义token请根据实际情况自行修改
    console.log('config: ', config.url)
    return config
  },
  error => {
    // do something with request error
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// 响应拦截器
service.interceptors.response.use(
  response => {
    console.log('response: ', response);
    const res = response.data
    console.log(`response响应: ${response.config.url}`, response.data)

    return res.data
  },
  error => {
    // 将后台返回的数据抛出啦
    console.log('error: ', error);
    // const status = error.response.status
    // console.log('status: ', status)
    return Promise.reject(error)
  }
)

export default service



